home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / prog / proxy14.arj / TOPSORT.PRX < prev   
Text File  |  1991-10-04  |  400b  |  12 lines

  1. // transforms a partial order into a total order
  2. // topsort: map(string,string) x set(string) -> seq(string)
  3.  
  4. topsort(g,nodes;x,n) { x={x:x<-nodes;x notin rng g};
  5.           if(x=={}) return [];
  6.           else n=oneof x;
  7.           return [n] conc topsort(g ds {n}, nodes diff {n});};
  8. nodes = {"c1","c2","c3","c4","c5"};
  9. g     = {"c1" -> "c3", "c2" -> "c3", "c2" -> "c4", "c3" -> "c5",
  10.       "c4" -> "c5"};
  11. end
  12.